home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
-
- #include "PlotTest.h"
- #include "ParseDemo.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TFPlotTest *FPlotTest;
- //---------------------------------------------------------------------------
- __fastcall TFPlotTest::TFPlotTest(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TFPlotTest::BExitClick(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TFPlotTest::PBPlotPaint(TObject *Sender)
- {
- TPaintBox *thePBPlot = (TPaintBox *)Sender;
- thePBPlot->Canvas->Pen->Color = clGray;
-
- //Draw coord
- thePBPlot->Canvas->MoveTo(0, thePBPlot->Height/2);
- thePBPlot->Canvas->LineTo(thePBPlot->Width, thePBPlot->Height/2);
- thePBPlot->Canvas->MoveTo(thePBPlot->Width/2, 0);
- thePBPlot->Canvas->LineTo(thePBPlot->Width/2, thePBPlot->Height);
-
- //Draw function
- PlotFunction(thePBPlot);
- }
- //---------------------------------------------------------------------------
-
- void TFPlotTest::PlotFunction(TPaintBox *thePBPlot)
- {
- thePBPlot->Canvas->Pen->Color = clBlack;
-
- int BaseIn;
- int BaseOut;
- int AngularUnit;
- char tempstr[50];
-
- //Get data (Base for Input/output and angular unit) from the main form
- FParser->GetBaseAndAngUnit(this, &BaseIn, &BaseOut, &AngularUnit);
-
- long double varValues[6];
- bool err = false;
-
- //Get data (values of the variables) from the main form
- err = FParser->GetVarValues(this, BaseIn, varValues);
- if (err)
- return;
-
- long double Result;
- AnsiString funcStr = MFunction->Text.c_str();
- long ctime = GetCurrentTime();
-
- Screen->Cursor = crHourGlass;
- //Create an sbParser object and receive its HANDLE
- HANDLE hParser = CreateNewParser(funcStr.c_str(), BaseIn, 6, "xyzuvw");
- Screen->Cursor = crDefault;
- if (GetIsError(hParser)) {
- char errText[50];
-
- //An error has occurred (see documentation)
- MessageBox(Handle, ldtochar(errText, GetGlobalError(hParser)),
- "Errornumber in Function (see documentation)",
- MB_ICONERROR);
-
- //Delete of the sbParser-object
- DeleteParser(hParser);
- return;
- }
- SetAngularUnitTo(hParser, AngularUnit);
-
- //Creation time
- ctime = GetCurrentTime() - ctime;
- LtheTime0->Caption = ldtochar(tempstr, (long double)ctime/1000, 12);
-
- long double diffx = 20/(long double)thePBPlot->Width;
- long double facty = 20/(long double)thePBPlot->Height;
- bool firstPlot = true;
- long plotxPos, plotyPos;
-
- //Reset time
- ctime = GetCurrentTime();
- Screen->Cursor = crHourGlass;
- if (err) {
- ctime = 0;
- }
- else
- {
- //Calculate and draw function
- for (long double xPos = -10; xPos <= 10; xPos = xPos+diffx) {
- varValues[0] = xPos;
-
- //Compute the result
- Result = GetResultExt(hParser, varValues);
- err = GetIsError(hParser);
-
- plotxPos = xPos*1/diffx+thePBPlot->Width/2+1;
- plotyPos = -1*Result*1/facty+thePBPlot->Height/2;
-
- //Plot out of drawing rect?
- if (plotyPos < 0) {
- plotyPos = -1;
- }
- if (plotyPos > thePBPlot->Height) {
- plotyPos = thePBPlot->Height;
- }
-
- //error: Jump over - else: plot
- if ((firstPlot == true) || (err == true)) {
- thePBPlot->Canvas->MoveTo(plotxPos, plotyPos);
- if (err == false) {
- firstPlot = false;
- }
- else {
- firstPlot = true;
- }
- }
- else
- thePBPlot->Canvas->LineTo(plotxPos, plotyPos);
- }
- }
- Screen->Cursor = crDefault;
-
- //Calculation time
- ctime = GetCurrentTime() - ctime;
- LtheTime->Caption = ldtochar(tempstr, (long double)ctime/1000, 12);
-
- //Delete of the sbParser-object
- DeleteParser(hParser);
- }
-
- void __fastcall TFPlotTest::FormShow(TObject *Sender)
- {
- this->MFunction->Lines = FParser->MFunction->Lines;
- LtheTime->Caption = "0";
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TFPlotTest::BRedrawClick(TObject *Sender)
- {
- PBPlot->Invalidate();
- }
- //---------------------------------------------------------------------------
-
-
-
-